package com.qf.bank.web.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.bank.userapi.api.UsersApi;
import com.qf.bank.userapi.po.UserCardInfo;
import com.qf.bank.userapi.po.Users;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/** 　* @描述: 用户管理 　* @时间: 2019/12/5 19:36 　 */
@RestController
@RequestMapping("/users")
public class UsersController {
  @Resource private UsersApi usersApi;

  /**
   * 查询单个用户
   *
   * @param userId
   * @return Users
   */
  @RequestMapping(value = "/{userId}", method = RequestMethod.GET)
  public Users getById(@PathVariable(value = "userId") int userId) {
    return usersApi.getById(userId);
  }

  /**
   * 根据用户id查询用户银行卡
   *
   * @param userId 用户id
   * @return 用户银行卡信息
   */
  @RequestMapping(value = "/{userId}/cardInfo", method = RequestMethod.GET)
  public UserCardInfo selectCardInfoByUserId(@PathVariable int userId) {
    return usersApi.selectCardInfoByUserId(userId);
  }

  /**
   * 用户分页
   *
   * @param current,size
   * @return Users
   */
  @RequestMapping(value = "/", method = RequestMethod.GET)
  public Page<Users> page(@RequestParam int current, @RequestParam int size) {
    return usersApi.page(current, size);
  }
  //     根据电话号查用户信息
  @RequestMapping(value = "/userPhone", method = RequestMethod.GET)
  public List<Users> getList(@RequestParam String userPhone) {
    return usersApi.getList(userPhone);
  }
  /** 　* @描述: 用户登录验证 　* @时间: 2019/12/5 13:30 　 */
  @RequestMapping(value = "/login", method = RequestMethod.POST)
  public Users getSelectLogin(@RequestBody Users users) {
    return usersApi.getSelectLogin(users);
  }

  /** 　* @描述: 添加用户 　* @时间: 2019/12/5 13:32 　 */
  @RequestMapping(value = "/", method = RequestMethod.POST)
  public Boolean setInsert(@RequestBody Users users) {
    return usersApi.setInsert(users);
  }

  /** 　* @描述: 根据用户id删除用户 　* @时间: 2019/12/5 13:50 　 */
  @RequestMapping(value = "/{userId}", method = RequestMethod.DELETE)
  public Boolean getDeleteId(@PathVariable(value = "userId") int userId) {
    return usersApi.getDeleteId(userId);
  }

  /** 　* @描述: 删除多个用户 　* @时间: 2019/12/5 13:53 　 */
  @RequestMapping(value = "/", method = RequestMethod.DELETE)
  public Boolean getDelete(@RequestBody List<Integer> list) {
    return usersApi.getDelete(list);
  }

  /** 　* @描述: 根据用户id修改用户信息(修改部分信息) 　* @时间: 2019/12/5 13:51 　 */
  @RequestMapping(value = "/", method = RequestMethod.PATCH)
  public Boolean getChangeId(@RequestBody Users users) {
    return usersApi.getChangeId(users);
  }
}
